<template>
    <el-form :inline="true" size="small" :model="form" class="form-inline">
        <el-form-item :label="item.label" v-for="(item, index) in defaults" :key="index">
            <el-input v-model.trim="form[item.field]" :placeholder="`请输入${item.label}`"  v-if="item.type=='input'" style="width: 100%;"></el-input>
            <el-select v-model="form[item.field]" :placeholder="`请输入${item.label}`" clearable  v-if="item.type=='select'"  style="width: 100%;">
                <el-option v-for="(m, n) in item.value" :key="n" :label="m.name" :value="m.code"></el-option>
            </el-select>

            <el-date-picker
            style="width: 100%;"
            v-if="item.type == 'dateTime'"
                v-model="form[item.field]"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
                </el-date-picker>
        </el-form-item>

        <el-form-item>
            <el-button type="success" size="small" @click="searchList">搜索113</el-button>
            <el-button type="default" size="small" @click="reset">重置</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
export default {
    props: ['defaults'],
    data() {
        return {
            form:{}
        }
    },
    methods: {
        searchList() {
            let oj = Object.assign({},this.form)
            let obj = {}
            for(var i in oj){
                let index = this.defaults.findIndex((el)=>{
                    return el.field == i
                })
                if(index != -1){
                    let el = this.defaults[index]
                    if(el.type == 'input'){
                        obj[el.field] = `${oj[i]}`  
                        obj[`${el.field}-op`] = 'ct'
                    }
                    if(el.type == 'checkBox'||el.type == 'select'){
               
                        if(oj[i]){
                           // let m = oj[i] + ""
                           // let ar = m.split("|").length!=0?m.split("|")[0]:m
                           // let values = el.value||[]
                         //   let i = values.findIndex((item)=>{
                            // return item.name == ar
                          //  })
                            
                            obj[el.field] = oj[i]
                            obj[`${el.field}-op`] = 'il'
                        }
                    }
            
                    if(el.type == 'dateTime'){
                        if(oj[i]){
                            var arr = oj[i].toString().split("-")
                            var time1 = arr.length!=0?arr[0]:''
                            var time2 = arr.length>1?arr[1]:''
                            obj[`${el.field}-0`] = time1
                            obj[`${el.field}-1`] = time2
                            obj[`${el.field}-op`] = 'bt'
                        }
                    }
                }
            }
            this.$emit('refreshList',obj)
            this.visible = false
        },
        reset() {
            this.form = {}
            this.$emit('reset',{})
        }
    }
}
</script>

<style scoped lang='scss'></style>